using System;
using UnityEngine;

public class Node : IComparable<Node>
{
    public Vector2Int gridPosition;
    public int gCost = 0; // 距起始节点的距离
    public int hCost = 0; // 距终点节点的距离
    public Node parentNode;

    public Node(Vector2Int gridPosition)
    {
        this.gridPosition = gridPosition;

        parentNode = null;
    }

    public int FCost
    {
        get
        {
            return gCost + hCost;
        }
    }

    public int CompareTo(Node nodeToCompare)
    {
        // 如果此实例 Fcost 小于 nodeToCompare.FCost，则 compare 将为 <0
        // 如果此实例 Fcost 大于 nodeToCompare.FCost，则 compare 将为 >0
        // 如果值相同，则 Compare 将为 ==0

        int compare = FCost.CompareTo(nodeToCompare.FCost);

        if (compare == 0)
        {
            compare = hCost.CompareTo(nodeToCompare.hCost);
        }

        return compare;
    }
}